<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
<title>IdeaLAN - Control Panel Installation.</title>

<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Geneva, sans-serif;
	font-size: 10px;
	color: #FFF;
}
body {
	background-color: #000;
}
a:link {
	color: #FFF;
	text-decoration: none;
}
a:visited {
	text-decoration: none;
	color: #FFF;
}
a:hover {
	text-decoration: underline;
	color: #FFF;
}
a:active {
	text-decoration: none;
	color: #FFF;
}
-->
</style></head>

<body>
<h2>Installing Control Panel </h2><br />

<?

/* LETS INCLUDE CONFIG FILE */
include("config.php");


/* LET'S GET VARIABLES FROM THE FORM */
$create = $_POST["create"]; 

$check = "SELECT * FROM `".$DBprefix."signup` WHERE `user_name` = 'admin' LIMIT 1";
$check_result = mysql_query($check); 

if ($check_result != "") {
	if (mysql_num_rows($check_result) > 0) { 
		$create = "NOGO";	
	} else {
		$create = "";
	}
}

if ($create != "") { $disable = "DISABLED"; }
	echo "	
<form name='install' method='POST' action='install.php'>
	<input type='submit' value='INSTALL' $disable />
	<input type='hidden' name='create' value='go' />
</form>

<p>&nbsp; </p>
	";
	


if ($create == "go") {
	

/* *** CREATE ACCESS TABLE *** */
$table_access = "CREATE TABLE `".$DBprefix."access` (
  userid smallint(5) NOT NULL,
  pageid smallint(5) NOT NULL,
  permission smallint(5) NOT NULL default '0',
  KEY userid (userid))";

	/* ---------- LET'S CREATE THE TABLE ---------- */
	$create1 = mysql_query($table_access); 
	
	/* LET'S DISPLAY RESULTS FROM CREATEING TABLE */
	if ($create1 == 1) { echo "CREATING TABLE: <i><b>ACCESS</b></i>........ <font color='#66FF00'><b>OK!</b></font> <br />"; } else { echo "CREATEING TABLE: <i><b>ACCESS</b></i>........ <font color='#FF0000'><b>ERROR!</b></font> ". mysql_errno() . " - " .  mysql_error() ."<br />"; }

/* *** CREATE ACCESS PAGES TABLE *** */
$table_access_pages = "CREATE TABLE `".$DBprefix."access_pages` (
  pageid smallint(5) NOT NULL auto_increment,
  pagename varchar(50) NOT NULL,
  pagesub varchar(50) NOT NULL,
  pageperm smallint(5) NOT NULL default '1',
  PRIMARY KEY  (pageid))";

	/* ---------- LET'S CREATE THE TABLE ---------- */
	$create2 = mysql_query($table_access_pages);
	
	/* LET'S DISPLAY RESULTS FROM CREATEING TABLE */
	if ($create2 == 1) { echo "CREATEING TABLE: <i><b>ACCESS PAGES</b></i>........ <font color='#66FF00'><b>OK!</b></font> <br />"; } else { echo "CREATEING TABLE: <i><b>ACCESS PAGES</b></i>........ <font color='#FF0000'><b>ERROR!</b></font> ". mysql_errno() . " - " .  mysql_error() ."<br />"; }

/* *** CREATE USER TABLE *** */
$table_logs = "CREATE TABLE `".$DBprefix."logs` (
  log_id int(10) NOT NULL auto_increment,
  log_action varchar(50) NOT NULL default '',
  log_userid smallint(5) NOT NULL default '0',
  log_page_to varchar(150) NOT NULL default '',
  log_page_from varchar(150) NOT NULL default '',
  log_ip varchar(15) NOT NULL default '',
  log_date int(50) NOT NULL default '0',
  log_indate int(50) NOT NULL default '0',
  log_outdate int(50) NOT NULL default '0',
  log_status varchar(50) NOT NULL default 'ACTIVE',
  log_errmsg varchar(255) NOT NULL default '',
  log_sesexp int(50) NOT NULL,
  log_sesid varchar(32) NOT NULL default '',
  UNIQUE KEY log_id (log_id))";
  
	/* ---------- LET'S CREATE THE TABLE ---------- */
	$create3 = mysql_query($table_logs);
	
	/* LET'S DISPLAY RESULTS FROM CREATEING TABLE */
	if ($create3 == 1) { echo "CREATEING TABLE: <i><b>LOGS</b></i>........ <font color='#66FF00'><b>OK!</b></font> <br />"; } else { echo "CREATEING TABLE: <i><b>LOGS</b></i>........ <font color='#FF0000'><b>ERROR!</b></font> ". mysql_errno() . " - " .  mysql_error() ."<br />"; }

/* *** CREATE USER TABLE *** */
$table_signup = "CREATE TABLE `".$DBprefix."signup` (
  user_id smallint(5) NOT NULL auto_increment,
  user_fname varchar(50) default NULL,
  user_lname varchar(50) default NULL,
  user_phone varchar(50) default NULL,
  user_name varchar(30) default NULL,
  user_pass varchar(32) default NULL,
  user_email varchar(32) default NULL,
  user_actnum varchar(32) default NULL,
  user_level tinyint(4) default NULL,
  user_adddate varchar(20) default NULL,
  user_lastlogin varchar(20) default NULL,
  user_logindns varchar(50) default NULL,
  user_loginfail varchar(20) default NULL,
  user_numloginfail tinyint(4) default NULL,
  user_set_timeout varchar(10) NOT NULL default '1200',
  user_set_lock smallint(2) NOT NULL default '0',
  PRIMARY KEY  (user_id))";
  
	/* ---------- LET'S CREATE THE TABLE ---------- */
	$create4 = mysql_query($table_signup);

	/* LET'S DISPLAY RESULTS FROM CREATEING TABLE */	
	if ($create4 == 1) { echo "CREATEING TABLE: <i><b>SIGNUP</b></i>........ <font color='#66FF00'><b>OK!</b></font> <br />"; } else { echo "CREATEING TABLE: <i><b>SIGNUP</b></i>........ <font color='#FF0000'><b>ERROR!</b></font> ". mysql_errno() . " - " .  mysql_error() ."<br />"; }


/* *** CREATE MODULE TABLE *** */
$table_modules = "CREATE TABLE `".$DBprefix."modules` (
  mod_id smallint(5) NOT NULL auto_increment,
  mod_name varchar(50) default NULL,
  mod_location varchar(50) default NULL,
  PRIMARY KEY  (mod_id))";
  
	/* ---------- LET'S CREATE THE TABLE ---------- */
	$create5 = mysql_query($table_modules);

	/* LET'S DISPLAY RESULTS FROM CREATEING TABLE */	
	if ($create5 == 1) { echo "CREATEING TABLE: <i><b>MODULES</b></i>........ <font color='#66FF00'><b>OK!</b></font> <br />"; } else { echo "CREATEING TABLE: <i><b>MODULES</b></i>........ <font color='#FF0000'><b>ERROR!</b></font> ". mysql_errno() . " - " .  mysql_error() ."<br />"; }



/* *** CREATE USER TABLE *** */
$table_todo = "CREATE TABLE `".$DBprefix."todo` (
  sid smallint(5) NOT NULL auto_increment,
  uid tinyint(5) default NULL,
  category smallint(5) NOT NULL default '0',
  title varchar(20) NOT NULL default '',
  description text NOT NULL,
  progress tinyint(5) default '0',
  add_date varchar(20) NOT NULL default '',
  fin_date varchar(20) NOT NULL default '',
  `status` tinyint(2) default '0',
  PRIMARY KEY  (sid))";
  
	/* ---------- LET'S CREATE THE TABLE ---------- */
	$create6 = mysql_query($table_todo);
  
	/* LET'S DISPLAY RESULTS FROM CREATEING TABLE */
	if ($create6 == 1) { echo "CREATEING TABLE: <i><b>TODO</b></i>........ <font color='#66FF00'><b>OK!</b></font> <br />"; } else { echo "CREATEING TABLE: <i><b>TODO</b></i>........ <font color='#FF0000'><b>ERROR!</b></font> ". mysql_errno() . " - " .  mysql_error() ."<br />"; }




	

	/* NOW THAT WE HAVE SUCCESSFULLY CREATED ALL THE TABLES LETS ADD A ADMIN ACCOUNT */
	if ($create4 == 1) {
		
		$add_admin = "INSERT INTO `".$DBprefix."signup` (`user_id` ,`user_fname` ,`user_lname` ,`user_phone` ,`user_name` ,`user_pass` ,`user_email` ,`user_actnum` ,`user_level` ,`user_adddate` ,`user_lastlogin` ,`user_logindns` ,`user_loginfail` ,`user_numloginfail` ,`user_set_timeout` ,`user_set_lock`) VALUES ('1', 'Admin', NULL , '1.203.599.1278', 'admin', '6f3249aa304055d63828af3bfab778f6', 'admin@idealan.net', '0', '5', UNIX_TIMESTAMP( ) , UNIX_TIMESTAMP( ) , 'office.idealan.net', UNIX_TIMESTAMP( ) , '0', '1200', '0'
)";
		$create7 = mysql_query($add_admin);
		
	/* LET'S CHECK IF THE ACCOUNT WAS CREATED SUCESSFULLY */
	
	if ($create7 == 1) { 
		echo "CREATEING ACCOUNT: <i><b>ADMIN</b></i>........ <font color='#66FF00'><b>OK!</b></font> <br /><br />"; 
		echo "
				<form name='form1' method='POST' action='login.php'>
				<lable>USERNAME: <input name='user_name' class='loguj' type='text' value='admin' readonly /></lable>
				<lable>PASSWORD: <input name='user_pass' class='loguj' type='text' value='31337' readonly /></lable>
				<input type='submit' class='logok' value='LOGIN' />
				</form>
				
			";

		} else { echo "CREATEING ACCOUNT: ADMIN</b></i>........ <font color='#FF0000'><b>ERROR!</b></font> ". mysql_errno() . " - " .  mysql_error() ."<br />"; }	
	}

} // END create = GO

?>

</body>
</html>